#include <bits/stdc++.h>

using namespace std;

class Solution
{
public:
    int countCompleteSubstrings(string word, int k)
    {
        int ans = 0, n = word.size();
        string_view s(word); // 使用string_view的时候substr不是拷贝
        for (int i = 0; i < n;)
        {
            int start = i;
            for (i++; i < n && abs(int(word[i]) - int(word[i - 1])) <= 2; i++)
                ;
            ans += subTask(s.substr(start, i - start), k);
        }
        return ans;
    }
    int subTask(string_view s, int k)
    {
        int ans = 0;

        for (int m = 1; k * m <= s.length() && m <= 26; ++m)
        {
            int cnt[26]{};
            auto check = [&]()
            {
                for (int i = 0; i < 26; i++)
                {
                    if (cnt[i] && cnt[i] != k)
                    {
                        return;
                    }
                }
                ans++;
            };
            for (int right = 0; right < s.length(); right++)
            {
                cnt[s[right] - 'a']++;
                int left = right + 1 - k * m;
                if (left >= 0)
                {
                    check();
                    cnt[s[left] - 'a']--;
                }
            }
        }
        return ans;
    }
};